$(document).ready(function(){
    
    $('#district').change(function(){
        get_geo_select_box($(this).val(), 'ward');
    });
    
    $('#city').change(function(){
        get_geo_select_box($(this).val(), 'district');
    });
    
        
    
});

function get_geo_select_box(parent_id, for_id){
    if(parent_id>0){
        var postData = 'parent_id='+parent_id;
        $.ajax({
            type: "POST",
            url: base_url + "ajax/ajax_geo/get_geo_by_parent_id_to_select_box",
            data: postData,
            dataType: 'json',
            success: function(res){
                if(res.status=='success'){
                    if(for_id=='district'){
                        $('#district').html('<option value="0">Quận/Huyện</option>'+res.html);
                    }
                    if(for_id=='ward'){
                        $('#ward').html('<option value="0">Xã/Phường</option>'+res.html);
                    }
                }
            }
        });
    }
}